stages:
  - analysis
  - test

.lab_custom_check:
  image: registry.gitlab.com/iu5edu/docker/uchardet:latest
  tags:
    - iu5edu
  rules:
    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
      changes:
        - ${LAB_DIR}/**/*
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
  variables:
    SRC_DIRECTORY: "${CI_PROJECT_DIR}/${LAB_DIR}"
  script:
    - git clone https://gitlab.com/iu5edu/cpp-course-sem2/tests.git
    - cd tests
    - bash encoding_check.sh
    - bash namespace_check.sh
    - bash include_cpp_check.sh

.lab_cppcheck:
  image: registry.gitlab.com/iu5edu/docker/cppcheck:latest
  tags:
    - iu5edu
  rules:
    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
      changes:
        - ${LAB_DIR}/**/*
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
  script:
    - cd ${CI_PROJECT_DIR}/${LAB_DIR}
    - cppcheck -q -j4 --enable=warning,style,performance,portability --error-exitcode=1 --std=c++17 .

.lab_cppcheck_lite:
  image: registry.gitlab.com/iu5edu/docker/cppcheck:latest
  tags:
    - iu5edu
  rules:
    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
      changes:
        - ${LAB_DIR}/**/*
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
  script:
    - cd ${CI_PROJECT_DIR}/${LAB_DIR}
    - cppcheck -q -j4 --enable=warning --error-exitcode=1 --std=c++17 .

.lab_test:
  image: registry.gitlab.com/iu5edu/docker/cpp-pytest:latest
  tags:
    - iu5edu
  rules:
    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
      changes:
        - ${LAB_DIR}/**/*
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual
  variables:
    WORK_DIRECTORY: "${CI_PROJECT_DIR}/${LAB_DIR}/cmake-build-debug"
    PROGRAM_UNDER_TEST: "./${LAB_DIR}"
  script:
    - cd ${CI_PROJECT_DIR}/${LAB_DIR}
    - cmake -S ./ -B ./cmake-build-debug/
    - cmake --build ./cmake-build-debug/
    - cd ${CI_PROJECT_DIR}
    - git clone https://gitlab.com/iu5edu/cpp-course-sem2/tests.git
    - cd tests/${LAB_DIR}
    - pytest tests.py --junitxml=${CI_PROJECT_DIR}/rspec.xml -s
  artifacts:
    when: always
    paths:
      - rspec.xml
    reports:
      junit: rspec.xml

# lab1
lab1_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab1"
  extends: .lab_custom_check

lab1_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab1"
  extends: .lab_cppcheck

lab1_test:
  stage: test
  variables:
    LAB_DIR: "lab1"
  extends: .lab_test

# lab2
lab2_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab2"
  extends: .lab_custom_check

lab2_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab2"
  extends: .lab_cppcheck

lab2_test:
  stage: test
  variables:
    LAB_DIR: "lab2"
  extends: .lab_test

# lab3
lab3_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab3"
  extends: .lab_custom_check

lab3_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab3"
  extends: .lab_cppcheck

lab3_test:
  stage: test
  variables:
    LAB_DIR: "lab3"
  extends: .lab_test

# lab4
lab4_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab4"
  extends: .lab_custom_check

lab4_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab4"
  extends: .lab_cppcheck

lab4_test:
  stage: test
  variables:
    LAB_DIR: "lab4"
  extends: .lab_test

# lab5
lab5_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab5"
  extends: .lab_custom_check

lab5_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab5"
  extends: .lab_cppcheck

lab5_test:
  stage: test
  variables:
    LAB_DIR: "lab5"
  extends: .lab_test

# lab6
lab6_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab6"
  extends: .lab_custom_check

lab6_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab6"
  extends: .lab_cppcheck

lab6_test:
  stage: test
  variables:
    LAB_DIR: "lab6"
  extends: .lab_test

# lab7
lab7_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab7"
  extends: .lab_custom_check

lab7_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab7"
  extends: .lab_cppcheck

lab7_test:
  stage: test
  variables:
    LAB_DIR: "lab7"
  extends: .lab_test

# lab8
lab8_custom_check:
  stage: analysis
  variables:
    LAB_DIR: "lab8"
  extends: .lab_custom_check

lab8_analysis:
  stage: analysis
  variables:
    LAB_DIR: "lab8"
  extends: .lab_cppcheck_lite

lab8_test:
  stage: test
  variables:
    LAB_DIR: "lab8"
  extends: .lab_test
